package com.store.webstore.controller;

import com.store.webstore.entity.Category;
import com.store.webstore.entity.Product;
import com.store.webstore.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 首页控制层
 */
@Controller
@RequestMapping("/user")
public class IndexController {
    @Autowired
    private IndexService indexService;
    @RequestMapping("/index")
    public String  index(Model model){
        //查询热门商品,精品商品
        List<Product> hotList = indexService.findHotProduct();
        model.addAttribute("hotList",hotList);
        List<Product> competList = indexService.findCompetList();
        model.addAttribute("competList",competList);
        return "index";
    }
    @RequestMapping("/category")
    @ResponseBody
    public List<Category> findCategory(){
        return indexService.findCategoryList();
    }



}
